﻿namespace HRM.CORE.REPORT
{
    using APP.HELPER.Utils.Language;
    using DevExpress.Utils;
    using DevExpress.XtraPrinting;
    using DevExpress.XtraReports.UI;
    using Dictionary.ERP;
    using HRM.CORE;
    using HRM.CORE.CLASS;
    using System; using Extra.ERP;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Drawing.Printing;

    public class rptListEmployee : XtraReport
    {
        private BottomMarginBand BottomMargin;
        private XRTableCell chSex;
        private XRTableCell colBirthday;
        private XRTableCell colBirthPlace;
        private XRTableCell colEmployeeCode;
        private XRTableCell colFirstName;
        private XRTableCell colLastName;
        private XRTableCell colMainAddress;
        private XRTableCell colOrder;
        private XRTableCell colPosition;
        private XRTableCell colSex;
        private IContainer components;
        private DetailBand Detail;
        private XRTableCell dtBirthday;
        private XRLabel dtDate;
        private GroupHeaderBand GroupHeader1;
        private HRM_EMPLOYEE l_Employee;
        private string m_Code;
        private int m_Level;
        private int m_Order;
        private ReportFooterBand ReportFooter;
        private ReportHeaderBand ReportHeader;
        private TopMarginBand TopMargin;
        private XRTableCell txtBirthPlace;
        private XRTableCell txtEmployeeAddress;
        private XRTableCell txtEmployeeCode;
        private XRTableCell txtFirstName;
        private XRTableCell txtLastName;
        private XRTableCell txtOrder;
        private XRTableCell txtPosition;
        private XRLabel txtTitle;
        private XRLabel txtUnit;
        private XRTable xrTable1;
        private XRTable xrTable2;
        private XRTableRow xrTableRow1;
        private XRTableRow xrTableRow2;

        public rptListEmployee()
        {
            this.l_Employee = new HRM_EMPLOYEE();
            this.m_Level = 0;
            this.m_Code = "";
            this.m_Order = 0;
            this.components = null;
            this.InitializeComponent();
            this.InitMultiLanguages();
        }

        public rptListEmployee(int Level, string Code)
        {
            this.l_Employee = new HRM_EMPLOYEE();
            this.m_Level = 0;
            this.m_Code = "";
            this.m_Order = 0;
            this.components = null;
            this.InitializeComponent();
            this.InitMultiLanguages();
            this.m_Level = Level;
            this.m_Code = Code;
        }

        private void chSex_BeforePrint(object sender, PrintEventArgs e)
        {
            try
            {
                if (Convert.ToBoolean(this.chSex.Text))
                {
                    this.chSex.Text = "Nam";
                }
                else
                {
                    this.chSex.Text = "Nữ";
                }
            }
            catch
            {
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void dtBirthday_BeforePrint(object sender, PrintEventArgs e)
        {
            try
            {
                this.dtBirthday.Text = Convert.ToDateTime(this.dtBirthday.Text).ToShortDateString();
            }
            catch
            {
            }
        }

        private void InitializeComponent()
        {
            this.Detail = new DetailBand();
            this.xrTable2 = new XRTable();
            this.xrTableRow2 = new XRTableRow();
            this.txtOrder = new XRTableCell();
            this.txtEmployeeCode = new XRTableCell();
            this.txtFirstName = new XRTableCell();
            this.txtLastName = new XRTableCell();
            this.dtBirthday = new XRTableCell();
            this.chSex = new XRTableCell();
            this.txtBirthPlace = new XRTableCell();
            this.txtEmployeeAddress = new XRTableCell();
            this.txtPosition = new XRTableCell();
            this.TopMargin = new TopMarginBand();
            this.dtDate = new XRLabel();
            this.BottomMargin = new BottomMarginBand();
            this.ReportHeader = new ReportHeaderBand();
            this.txtTitle = new XRLabel();
            this.txtUnit = new XRLabel();
            this.GroupHeader1 = new GroupHeaderBand();
            this.xrTable1 = new XRTable();
            this.xrTableRow1 = new XRTableRow();
            this.colOrder = new XRTableCell();
            this.colEmployeeCode = new XRTableCell();
            this.colFirstName = new XRTableCell();
            this.colLastName = new XRTableCell();
            this.colBirthday = new XRTableCell();
            this.colSex = new XRTableCell();
            this.colBirthPlace = new XRTableCell();
            this.colMainAddress = new XRTableCell();
            this.colPosition = new XRTableCell();
            this.ReportFooter = new ReportFooterBand();
            this.xrTable2.BeginInit();
            this.xrTable1.BeginInit();
            this.BeginInit();
            this.Detail.Controls.AddRange(new XRControl[] { this.xrTable2 });
            this.Detail.HeightF = 29.16667f;
            this.Detail.Name = "Detail";
            this.Detail.Padding = new PaddingInfo(0, 0, 0, 0, 100f);
            this.Detail.TextAlignment = TextAlignment.TopLeft;
            this.xrTable2.Borders = BorderSide.Bottom | BorderSide.Right | BorderSide.Left;
            this.xrTable2.LocationFloat = new PointFloat(0f, 0f);
            this.xrTable2.Name = "xrTable2";
            this.xrTable2.Rows.AddRange(new XRTableRow[] { this.xrTableRow2 });
            this.xrTable2.SizeF = new SizeF(1039f, 29.16667f);
            this.xrTable2.StylePriority.UseBorders = false;
            this.xrTableRow2.Cells.AddRange(new XRTableCell[] { this.txtOrder, this.txtEmployeeCode, this.txtFirstName, this.txtLastName, this.dtBirthday, this.chSex, this.txtBirthPlace, this.txtEmployeeAddress, this.txtPosition });
            this.xrTableRow2.Name = "xrTableRow2";
            this.xrTableRow2.Weight = 1.0;
            this.txtOrder.Name = "txtOrder";
            this.txtOrder.Padding = new PaddingInfo(4, 0, 0, 0, 100f);
            this.txtOrder.StylePriority.UsePadding = false;
            this.txtOrder.StylePriority.UseTextAlignment = false;
            this.txtOrder.Text = "txtOrder";
            this.txtOrder.TextAlignment = TextAlignment.MiddleLeft;
            this.txtOrder.Weight = 0.18749981602642024;
            this.txtOrder.BeforePrint += new PrintEventHandler(this.txtOrder_BeforePrint);
            this.txtEmployeeCode.Name = "txtEmployeeCode";
            this.txtEmployeeCode.Padding = new PaddingInfo(4, 0, 0, 0, 100f);
            this.txtEmployeeCode.StylePriority.UsePadding = false;
            this.txtEmployeeCode.StylePriority.UseTextAlignment = false;
            this.txtEmployeeCode.Text = "[EmployeeCode]";
            this.txtEmployeeCode.TextAlignment = TextAlignment.MiddleLeft;
            this.txtEmployeeCode.Weight = 0.50972208430404586;
            this.txtFirstName.Name = "txtFirstName";
            this.txtFirstName.Padding = new PaddingInfo(4, 0, 0, 0, 100f);
            this.txtFirstName.StylePriority.UsePadding = false;
            this.txtFirstName.StylePriority.UseTextAlignment = false;
            this.txtFirstName.Text = "[FirstName]";
            this.txtFirstName.TextAlignment = TextAlignment.MiddleLeft;
            this.txtFirstName.Weight = 0.63611097551659967;
            this.txtLastName.Name = "txtLastName";
            this.txtLastName.Padding = new PaddingInfo(4, 0, 0, 0, 100f);
            this.txtLastName.StylePriority.UsePadding = false;
            this.txtLastName.StylePriority.UseTextAlignment = false;
            this.txtLastName.Text = "[LastName]";
            this.txtLastName.TextAlignment = TextAlignment.MiddleLeft;
            this.txtLastName.Weight = 0.28333369813443543;
            this.dtBirthday.Name = "dtBirthday";
            this.dtBirthday.Padding = new PaddingInfo(4, 0, 0, 0, 100f);
            this.dtBirthday.StylePriority.UsePadding = false;
            this.dtBirthday.StylePriority.UseTextAlignment = false;
            this.dtBirthday.Text = "[BirthdayDay]/[BirthdayMonth]/[BirthdayYear]";
            this.dtBirthday.TextAlignment = TextAlignment.MiddleLeft;
            this.dtBirthday.Weight = 0.408944209647367;
            this.dtBirthday.BeforePrint += new PrintEventHandler(this.dtBirthday_BeforePrint);
            this.chSex.Name = "chSex";
            this.chSex.Padding = new PaddingInfo(4, 0, 0, 0, 100f);
            this.chSex.StylePriority.UsePadding = false;
            this.chSex.StylePriority.UseTextAlignment = false;
            this.chSex.Text = "[Sex]";
            this.chSex.TextAlignment = TextAlignment.MiddleCenter;
            this.chSex.Weight = 0.36195866288386475;
            this.chSex.BeforePrint += new PrintEventHandler(this.chSex_BeforePrint);
            this.txtBirthPlace.Name = "txtBirthPlace";
            this.txtBirthPlace.Padding = new PaddingInfo(4, 0, 0, 0, 100f);
            this.txtBirthPlace.StylePriority.UsePadding = false;
            this.txtBirthPlace.StylePriority.UseTextAlignment = false;
            this.txtBirthPlace.Text = "[BirthPlace]";
            this.txtBirthPlace.TextAlignment = TextAlignment.MiddleLeft;
            this.txtBirthPlace.Weight = 0.80640229250794482;
            this.txtEmployeeAddress.Name = "txtEmployeeAddress";
            this.txtEmployeeAddress.Padding = new PaddingInfo(4, 0, 0, 0, 100f);
            this.txtEmployeeAddress.StylePriority.UsePadding = false;
            this.txtEmployeeAddress.StylePriority.UseTextAlignment = false;
            this.txtEmployeeAddress.Text = "[MainAddress]";
            this.txtEmployeeAddress.TextAlignment = TextAlignment.MiddleLeft;
            this.txtEmployeeAddress.Weight = 1.4794734176589024;
            this.txtPosition.Name = "txtPosition";
            this.txtPosition.Padding = new PaddingInfo(4, 0, 0, 0, 100f);
            this.txtPosition.StylePriority.UsePadding = false;
            this.txtPosition.StylePriority.UseTextAlignment = false;
            this.txtPosition.Text = "[Position]";
            this.txtPosition.TextAlignment = TextAlignment.MiddleLeft;
            this.txtPosition.Weight = 0.86788850217458613;
            this.TopMargin.Controls.AddRange(new XRControl[] { this.dtDate });
            this.TopMargin.HeightF = 31f;
            this.TopMargin.Name = "TopMargin";
            this.TopMargin.Padding = new PaddingInfo(0, 0, 0, 0, 100f);
            this.TopMargin.TextAlignment = TextAlignment.TopLeft;
            this.dtDate.LocationFloat = new PointFloat(851.2709f, 10.00002f);
            this.dtDate.Name = "dtDate";
            this.dtDate.Padding = new PaddingInfo(2, 2, 0, 0, 100f);
            this.dtDate.SizeF = new SizeF(187.7291f, 17.99998f);
            this.dtDate.StylePriority.UseTextAlignment = false;
            this.dtDate.Text = "dtDate";
            this.dtDate.TextAlignment = TextAlignment.MiddleRight;
            this.BottomMargin.HeightF = 56f;
            this.BottomMargin.Name = "BottomMargin";
            this.BottomMargin.Padding = new PaddingInfo(0, 0, 0, 0, 100f);
            this.BottomMargin.TextAlignment = TextAlignment.TopLeft;
            this.ReportHeader.Controls.AddRange(new XRControl[] { this.txtTitle, this.txtUnit });
            this.ReportHeader.HeightF = 55f;
            this.ReportHeader.Name = "ReportHeader";
            this.txtTitle.Font = new Font("Times New Roman", 16f, FontStyle.Bold);
            this.txtTitle.LocationFloat = new PointFloat(0f, 0f);
            this.txtTitle.Name = "txtTitle";
            this.txtTitle.Padding = new PaddingInfo(2, 2, 0, 0, 100f);
            this.txtTitle.SizeF = new SizeF(1039f, 30.25001f);
            this.txtTitle.StylePriority.UseFont = false;
            this.txtTitle.StylePriority.UseTextAlignment = false;
            this.txtTitle.Text = "DANH S\x00c1CH NH\x00c2N VI\x00caN";
            this.txtTitle.TextAlignment = TextAlignment.MiddleCenter;
            this.txtUnit.LocationFloat = new PointFloat(0f, 30.25001f);
            this.txtUnit.Name = "txtUnit";
            this.txtUnit.Padding = new PaddingInfo(2, 2, 0, 0, 100f);
            this.txtUnit.SizeF = new SizeF(1039f, 17.70834f);
            this.txtUnit.StylePriority.UseTextAlignment = false;
            this.txtUnit.TextAlignment = TextAlignment.MiddleCenter;
            this.GroupHeader1.Controls.AddRange(new XRControl[] { this.xrTable1 });
            this.GroupHeader1.HeightF = 28.125f;
            this.GroupHeader1.Name = "GroupHeader1";
            this.xrTable1.AnchorVertical = VerticalAnchorStyles.Bottom;
            this.xrTable1.BackColor = Color.WhiteSmoke;
            this.xrTable1.Borders = BorderSide.All;
            this.xrTable1.LocationFloat = new PointFloat(4.577637E-05f, 0f);
            this.xrTable1.Name = "xrTable1";
            this.xrTable1.Rows.AddRange(new XRTableRow[] { this.xrTableRow1 });
            this.xrTable1.SizeF = new SizeF(1039f, 28.125f);
            this.xrTable1.StylePriority.UseBackColor = false;
            this.xrTable1.StylePriority.UseBorders = false;
            this.xrTableRow1.Cells.AddRange(new XRTableCell[] { this.colOrder, this.colEmployeeCode, this.colFirstName, this.colLastName, this.colBirthday, this.colSex, this.colBirthPlace, this.colMainAddress, this.colPosition });
            this.xrTableRow1.Name = "xrTableRow1";
            this.xrTableRow1.Weight = 1.0;
            this.colOrder.CanGrow = false;
            this.colOrder.Font = new Font("Times New Roman", 9.75f, FontStyle.Bold);
            this.colOrder.Name = "colOrder";
            this.colOrder.StylePriority.UseFont = false;
            this.colOrder.StylePriority.UseTextAlignment = false;
            this.colOrder.Text = "STT";
            this.colOrder.TextAlignment = TextAlignment.MiddleCenter;
            this.colOrder.Weight = 0.18749992582046493;
            this.colEmployeeCode.CanGrow = false;
            this.colEmployeeCode.Font = new Font("Times New Roman", 9.75f, FontStyle.Bold);
            this.colEmployeeCode.Name = "colEmployeeCode";
            this.colEmployeeCode.StylePriority.UseFont = false;
            this.colEmployeeCode.StylePriority.UseTextAlignment = false;
            this.colEmployeeCode.Text = "M\x00e3 NV";
            this.colEmployeeCode.TextAlignment = TextAlignment.MiddleCenter;
            this.colEmployeeCode.Weight = 0.50972216874420684;
            this.colFirstName.CanGrow = false;
            this.colFirstName.Font = new Font("Times New Roman", 9.75f, FontStyle.Bold);
            this.colFirstName.Name = "colFirstName";
            this.colFirstName.StylePriority.UseFont = false;
            this.colFirstName.StylePriority.UseTextAlignment = false;
            this.colFirstName.Text = "Họ l\x00f3t";
            this.colFirstName.TextAlignment = TextAlignment.MiddleCenter;
            this.colFirstName.Weight = 0.63611084903845827;
            this.colLastName.CanGrow = false;
            this.colLastName.Font = new Font("Times New Roman", 9.75f, FontStyle.Bold);
            this.colLastName.Name = "colLastName";
            this.colLastName.StylePriority.UseFont = false;
            this.colLastName.StylePriority.UseTextAlignment = false;
            this.colLastName.Text = "T\x00ean";
            this.colLastName.TextAlignment = TextAlignment.MiddleCenter;
            this.colLastName.Weight = 0.28333359176452011;
            this.colBirthday.CanGrow = false;
            this.colBirthday.Font = new Font("Times New Roman", 9.75f, FontStyle.Bold);
            this.colBirthday.Name = "colBirthday";
            this.colBirthday.StylePriority.UseFont = false;
            this.colBirthday.StylePriority.UseTextAlignment = false;
            this.colBirthday.Text = "Ng\x00e0y sinh";
            this.colBirthday.TextAlignment = TextAlignment.MiddleCenter;
            this.colBirthday.Weight = 0.40894431185845292;
            this.colSex.CanGrow = false;
            this.colSex.Font = new Font("Times New Roman", 9.75f, FontStyle.Bold);
            this.colSex.Name = "colSex";
            this.colSex.StylePriority.UseFont = false;
            this.colSex.StylePriority.UseTextAlignment = false;
            this.colSex.Text = "Giới t\x00ednh";
            this.colSex.TextAlignment = TextAlignment.MiddleCenter;
            this.colSex.Weight = 0.36195831196209949;
            this.colBirthPlace.CanGrow = false;
            this.colBirthPlace.Font = new Font("Times New Roman", 9.75f, FontStyle.Bold);
            this.colBirthPlace.Name = "colBirthPlace";
            this.colBirthPlace.StylePriority.UseFont = false;
            this.colBirthPlace.StylePriority.UseTextAlignment = false;
            this.colBirthPlace.Text = "Nơi sinh";
            this.colBirthPlace.TextAlignment = TextAlignment.MiddleCenter;
            this.colBirthPlace.Weight = 0.80640272041744154;
            this.colMainAddress.CanGrow = false;
            this.colMainAddress.Font = new Font("Times New Roman", 9.75f, FontStyle.Bold);
            this.colMainAddress.Name = "colMainAddress";
            this.colMainAddress.StylePriority.UseFont = false;
            this.colMainAddress.StylePriority.UseTextAlignment = false;
            this.colMainAddress.Text = "Địa chỉ";
            this.colMainAddress.TextAlignment = TextAlignment.MiddleCenter;
            this.colMainAddress.Weight = 1.4794726391316035;
            this.colPosition.CanGrow = false;
            this.colPosition.Font = new Font("Times New Roman", 9.75f, FontStyle.Bold);
            this.colPosition.Name = "colPosition";
            this.colPosition.StylePriority.UseFont = false;
            this.colPosition.StylePriority.UseTextAlignment = false;
            this.colPosition.Text = "Chức vụ";
            this.colPosition.TextAlignment = TextAlignment.MiddleCenter;
            this.colPosition.Weight = 0.86788870410009622;
            this.ReportFooter.HeightF = 10f;
            this.ReportFooter.Name = "ReportFooter";
            base.Bands.AddRange(new Band[] { this.Detail, this.TopMargin, this.BottomMargin, this.ReportHeader, this.GroupHeader1, this.ReportFooter });
            base.Font = new Font("Times New Roman", 9.75f);
            base.Landscape = true;
            base.Margins = new Margins(0x47, 0x3b, 0x1f, 0x38);
            base.PageHeight = 0x33b;
            base.PageWidth = 0x491;
            base.PaperKind = PaperKind.A4;
            base.Version = "9.3";
            this.BeforePrint += new PrintEventHandler(this.rptListEmployee_BeforePrint);
            this.xrTable2.EndInit();
            this.xrTable1.EndInit();
            this.EndInit();
        }

        private void InitMultiLanguages()
        {
            this.colOrder.Text = MultiLanguages.GetString("tbl_HRM_EMPLOYEE", "No", this.colOrder.Text);
            this.colEmployeeCode.Text = MultiLanguages.GetString("tbl_HRM_EMPLOYEE", "EmployeeCode", this.colEmployeeCode.Text);
            this.colFirstName.Text = MultiLanguages.GetString("tbl_HRM_EMPLOYEE", "FirstName", this.colFirstName.Text);
            this.colLastName.Text = MultiLanguages.GetString("tbl_HRM_EMPLOYEE", "LastName", this.colLastName.Text);
            this.colSex.Text = MultiLanguages.GetString("tbl_HRM_EMPLOYEE", "Sex", this.colSex.Text);
            this.colBirthday.Text = MultiLanguages.GetString("tbl_HRM_EMPLOYEE", "Birthday", this.colBirthday.Text);
            this.colBirthPlace.Text = MultiLanguages.GetString("tbl_HRM_EMPLOYEE", "Birthplace", this.colBirthPlace.Text);
            this.colMainAddress.Text = MultiLanguages.GetString("tbl_HRM_EMPLOYEE", "MainAddress", this.colMainAddress.Text);
            this.colPosition.Text = MultiLanguages.GetString("tbl_HRM_EMPLOYEE", "Position", this.colPosition.Text);
        }

        private void LoadLevel()
        {
            if (this.m_Level == 1)
            {
                HRM_BRANCH hrm_branch = new HRM_BRANCH();
                hrm_branch.Get(this.m_Code);
                this.txtUnit.Text = "Đơn vị: " + hrm_branch.BranchName;
            }
            else if (this.m_Level == 2)
            {
                HRM_DEPARTMENT hrm_department = new HRM_DEPARTMENT();
                hrm_department.Get(this.m_Code);
                this.txtUnit.Text = "Đơn vị: " + hrm_department.DepartmentName;
            }
            else if (this.m_Level == 3)
            {
                HRM_GROUP hrm_group = new HRM_GROUP();
                hrm_group.Get(this.m_Code);
                this.txtUnit.Text = "Đơn vị: " + hrm_group.GroupName;
            }
        }

        private void LoadListEmployee()
        {
            this.txtTitle.Text = "DANH S\x00c1CH NH\x00c2N VI\x00caN";
            DataSet set = new DataSet();
            DataTable table = new DataTable();
            table = this.l_Employee.GetListCurrentNow(this.m_Level, this.m_Code, 1);
            set.Tables.Add(table);
            base.DataSource = set;
            base.DataMember = table.TableName;
            base.DataAdapter = table;
        }

        private void rptListEmployee_BeforePrint(object sender, PrintEventArgs e)
        {
            this.LoadLevel();
            this.LoadListEmployee();
            this.dtDate.Text = DateTime.Now.ToShortDateString();
            CreateHeaderReport.CreateHeader(this.ReportHeader);
            CreateFooterReport.CreateFooter("IsOther", this.ReportFooter, this);
        }

        private void txtOrder_BeforePrint(object sender, PrintEventArgs e)
        {
            this.m_Order++;
            this.txtOrder.Text = this.m_Order.ToString();
        }
    }
}

